package com.yaoxuguang.concurrence.wait_notify.producer_consumer.ontToOne;

import sun.plugin.cache.CacheUpdateHelper;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.wait_notify.producer_consumer.ontToOne
 * @Description: 测试生产消费模式（一对一）
 * @date 2018年12月21日18:07
 */
public class Run {
    public static void main(String[] args) {
        try {
            String str = new String("");

            Producer producer = new Producer(str);
            Consumer consumer = new Consumer(str);

       /* ThreadP p = new ThreadP(producer);
        p.start();

        ThreadC c = new ThreadC(consumer);
        c.start();*/

            ThreadP [] p = new ThreadP[2];
            ThreadC [] c = new ThreadC[2];

            for (int i = 0; i < 2; i++) {
                p[i] = new ThreadP(producer);
                p[i].setName("生产者"+(i+1));
                c[i] = new ThreadC(consumer);
                c[i].setName("消费者"+(i+1));
                p[i].start();
                c[i].start();
            }

            Thread.sleep(5000);
            Thread [] threadArray = new Thread[Thread.currentThread().getThreadGroup().activeCount()];
            Thread.currentThread().getThreadGroup().enumerate(threadArray);
            for (int i = 0; i < threadArray.length; i++) {
                System.out.println(threadArray[i].getName()+" "+threadArray[i].getState());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
